This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Cannot access member "hex" for type "ByteString"
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Jeffrey.Kintscher, anacrolix, eric.smith
Priority: normal Keywords:

Created on 2020-08-17 02:50 by anacrolix, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
hex.py anacrolix, 2020-08-24 01:22
Messages (8)
msg375523 - (view) Author: Matt Joiner (anacrolix) Date: 2020-08-17 02:50
I get this error when running pyright for a type of typing.ByteString. All the implementations of ByteString (bytes, bytearray, memoryview) have the hex method, so this seems unexpected?
msg375528 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-08-17 06:49
Without some example code that shows the problem we can't help you. Have you considered that this is a bug with pyright, not a bug with python itself?
msg375553 - (view) Author: Matt Joiner (anacrolix) Date: 2020-08-17 15:06
https://github.com/python/cpython/blob/48b069a003ba6c684a9ba78493fbbec5e89f10b8/Lib/_collections_abc.py#L953

https://github.com/python/cpython/blob/0e95bbf08571e98f4b688524efc2dcf20d315d91/Lib/typing.py#L1612
msg375554 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-08-17 15:17
We need to know how to trigger the problem you're seeing. You need to provide code we can run that shows the error you're seeing.
msg375831 - (view) Author: Matt Joiner (anacrolix) Date: 2020-08-24 01:23
$ pyright hex.py 
stubPath /Users/anacrolix/src/dht-scraper/typings is not a valid directory.
Assuming Python platform Darwin
Searching for source files
Found 1 source file
/Users/anacrolix/src/dht-scraper/hex.py
  3:9 - error: Cannot access member "hex" for type "ByteString"
  Member "hex" is unknown (reportGeneralTypeIssues)
1 error, 0 warnings 
Completed in 0.562sec
anacrolix@anacrolix-mbp-2018:~/src/dht-scraper$ mypy hex.py 
hex.py:3: error: "ByteString" has no attribute "hex"
Found 1 error in 1 file (checked 1 source file)
anacrolix@anacrolix-mbp-2018:~/src/dht-scraper$ python3 hex.py 
deadbeef
msg375832 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-08-24 01:27
This looks like a problem in pyright, not in CPython.
msg375833 - (view) Author: Matt Joiner (anacrolix) Date: 2020-08-24 01:31
I do not think so. mypy has the same issue. The ByteString type does not include the methods shared by all its implementations. I already linked to this in https://bugs.python.org/msg375553. I also showed that mypy doesn't work in my last comment.
msg375834 - (view) Author: Jeffrey Kintscher (Jeffrey.Kintscher) * Date: 2020-08-24 02:06
hex.py works for me with CPython versions 3.5, 3.7, 3.8, and 3.9, and the master branch.
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85736
2020-08-24 02:06:57Jeffrey.Kintschersetmessages: + msg375834
2020-08-24 01:31:59anacrolixsetmessages: + msg375833
2020-08-24 01:27:20eric.smithsetmessages: + msg375832
2020-08-24 01:23:27anacrolixsetmessages: + msg375831
2020-08-24 01:22:06anacrolixsetfiles: + hex.py
2020-08-20 04:50:28Jeffrey.Kintschersetstatus: pending -> open
nosy: + Jeffrey.Kintscher
2020-08-18 07:10:50eric.smithsetstatus: open -> pending
2020-08-17 15:17:09eric.smithsetmessages: + msg375554
2020-08-17 15:06:00anacrolixsetstatus: pending -> open

messages: + msg375553
2020-08-17 06:49:15eric.smithsetstatus: open -> pending
nosy: + eric.smith
messages: + msg375528

2020-08-17 02:50:34anacrolixcreate