[issue44140] WeakKeyDictionary should support lookup by id instead of hash

2021-05-15 Thread conchylicultor
New submission from conchylicultor : WeakKeyDictionary are great to "associate additional data with an object owned by other parts of an application", as quoted from the doc: https://docs.python.org/3/library/weakref.html#weakref.WeakKeyDictionary However, this currently

[issue43746] Weird typing annotation closure behavior

2021-04-09 Thread conchylicultor
conchylicultor added the comment: Yes, I know I can rename the closure, or wrap the annotation in 'quote'. I just wanted to point this out as it felt confusing to me. For instance, it feels inconsistent with: ``` def fn(datetime: datetime.Time): # Works as expected ``` Or: ``` @dataclass

[issue43746] Weird typing annotation closure behavior

2021-04-09 Thread conchylicultor
conchylicultor added the comment: Sure, here is a minimal reproductible example demonstrating the issue: ``` import pathlib class C: pathlib: pathlib.Path = None ``` Which raises: ``` File "py", line 5, in C pathlib: pathlib.Path = None AttributeError: 'NoneType'

[issue43746] Weird typing annotation closure behavior

2021-04-08 Thread conchylicultor
conchylicultor added the comment: The above example is a real world example I have currently have. Basically I have some dataclass based configuration like: in losses.py: ``` class LossesParams: ... ``` in dataset.py: ``` class DatasetParams: ... ``` in config.py

[issue43746] Weird typing annotation closure behavior

2021-04-08 Thread conchylicultor
conchylicultor added the comment: > Do you have an actual use case for self-referential annotations? I'm not sure I understand the question. My use case is the following: ``` from ... import losses class A: losses: losses.Losses = losses.Losses() ``` Currently this is failing be ca

[issue43746] Weird typing annotation closure behavior

2021-04-06 Thread conchylicultor
conchylicultor added the comment: Interestingly mypy, pylint correctly resolve the closure. ``` class A: dataclasses: dataclasses.Field = dataclasses.field() A.dataclasses.other # mypy error: "Field[Any]" has no attribute "other" ``` So the current workaro

[issue43746] Weird typing annotation closure behavior

2021-04-06 Thread conchylicultor
Change by conchylicultor : -- components: +Library (Lib) -Interpreter Core ___ Python tracker <https://bugs.python.org/issue43746> ___ ___ Python-bugs-list mailin

[issue43746] Weird typing annotation closure behavior

2021-04-06 Thread conchylicultor
Change by conchylicultor : -- components: +Interpreter Core type: -> behavior versions: +Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issu

[issue43746] Weird typing annotation closure behavior

2021-04-06 Thread conchylicultor
New submission from conchylicultor : I observe some strange closure behavior for typing annotations when the name is defined ``` x: x = 1 # Works, __annotation__ == {'x': 1} ``` This creates issue, for example: ``` from ... import losses class A: # AttributeError: 'Losses' object has

[issue33129] Add kwarg-only option to dataclass

2020-12-16 Thread conchylicultor
conchylicultor added the comment: For the API, I think we could add this feature with a single new `dataclass(kw_only: bool | str)` ``` @dataclasses.dataclass(kw_only=True) class A: a: int b: int c: int # A(*, a, b, c) @dataclasses.dataclass(kw_only='b') class A: a: int b: int

[issue39106] Add suggestions to argparse error message output for unrecognized arguments

2020-12-11 Thread conchylicultor
conchylicultor added the comment: I don't think this should have been closed. [1] If the user is using sub_parser, the options are not even displayed. For example in our https://github.com/tensorflow/datasets project: ``` $ tfds build mnist --overwritte usage: tfds [-h] [--helpfull

[issue42512] Confusing that BinaryIO and IO[bytes] cannot be used interchangeably

2020-11-30 Thread conchylicultor
Change by conchylicultor : -- components: +Library (Lib) type: -> behavior versions: +Python 3.10 ___ Python tracker <https://bugs.python.org/issu

[issue42512] Confusing that BinaryIO and IO[bytes] cannot be used interchangeably

2020-11-30 Thread conchylicultor
New submission from conchylicultor : Currently, because `BinaryIO` is subclass of `IO[bytes]`, the 2 cannot be used interchangeably. Example with pytype: ``` def iter_zip(arch_f) -> List[typing.BinaryIO]]: with open(arch_f, 'rb') as fobj: z = zipfile.ZipFile(fobj) return [z.o

[issue33129] Add kwarg-only option to dataclass

2020-11-11 Thread conchylicultor
conchylicultor added the comment: Solving this would significantly improve @dataclass inheritance (https://bugs.python.org/issue39300). Any idea when this will land ? Currently, it is not possible to add required argument to a child dataclass (unless hacks like duplicating attributes

[issue42090] zipfile.Path.joinpath API inconsistent with pathlib.Path.joinpath

2020-10-19 Thread conchylicultor
New submission from conchylicultor : The following code fail with zipfile.Path, but works with pathlib.Path: ``` path = path.joinpath().joinpath('other', 'other') ``` Zipfile: https://github.com/python/cpython/blob/95ad890a7b0341d8d2fde13f824bc24c65a8ece0/Lib/zipfile.py#L2363 ``` def

[issue42052] pathlib.Path should not call str() internally to allow inheritance

2020-10-16 Thread conchylicultor
conchylicultor added the comment: Closing this as I realize that even if this was solved, it would still not fully resolve the issue. Basically I want to control how __fspath__ and __str__ behave externally (for users), but internal fspath and str should always call `super

[issue42052] pathlib.Path should not call str() internally to allow inheritance

2020-10-16 Thread conchylicultor
New submission from conchylicultor : I'm writing a subclass of `pathlib.Path` with custom `__fspath__`. To prevent bad usages (users should use `os.fspath(path)` instead of `str(path)` to access the underlying path), I would like to overwrite `str`: ``` class MyPath(pathlib.PosixPath