[issue46511] dataclasses: Allow typing.Annotated to wrap dataclasses-specific annotations

2022-02-11 Thread Gregory Beauregard
Gregory Beauregard added the comment: It occurred to be that we do need to add the __call__ to KW_ONLY, but for a different reason than this bpo: If you call get_type_hints on a dataclass with a KW_ONLY parameter when PEP 563 is enabled, the entire call will fail if KW_ONLY isn't callable

[issue46643] typing.Annotated cannot wrap typing.ParamSpec args/kwargs

2022-02-09 Thread Gregory Beauregard
Gregory Beauregard added the comment: I wrote a PR that fixes the underlying issue here, but I'm leaving it as a draft while the discussion plays out. I think the stuff currently in the patch should be okay regardless of the discussion decision, because the underlying issue is that P.args

[issue46643] typing.Annotated cannot wrap typing.ParamSpec args/kwargs

2022-02-09 Thread Gregory Beauregard
Change by Gregory Beauregard : -- keywords: +patch pull_requests: +29408 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31238 ___ Python tracker <https://bugs.python.org/issu

[issue46643] typing.Annotated cannot wrap typing.ParamSpec args/kwargs

2022-02-08 Thread Gregory Beauregard
Gregory Beauregard added the comment: I have made a thread on typing-sig to discuss this: https://mail.python.org/archives/list/typing-...@python.org/thread/WZ4BCFO4VZ7U4CZ4FSDQNFAKPG2KOGCL/ -- ___ Python tracker <https://bugs.python.

[issue46643] typing.Annotated cannot wrap typing.ParamSpec args/kwargs

2022-02-08 Thread Gregory Beauregard
Gregory Beauregard added the comment: My general understanding has been that since Annotated exists primarily to allow interoperability between typing and non-typing uses of annotation space, and that this is quite clear in the PEP, most cases where this is not allowed (_especially_

[issue46676] ParamSpec args and kwargs are not equal to themselves.

2022-02-07 Thread Gregory Beauregard
Change by Gregory Beauregard : -- pull_requests: +29380 pull_request: https://github.com/python/cpython/pull/31210 ___ Python tracker <https://bugs.python.org/issue46

[issue46676] ParamSpec args and kwargs are not equal to themselves.

2022-02-07 Thread Gregory Beauregard
Change by Gregory Beauregard : -- keywords: +patch pull_requests: +29373 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31203 ___ Python tracker <https://bugs.python.org/issu

[issue46676] ParamSpec args and kwargs are not equal to themselves.

2022-02-07 Thread Gregory Beauregard
New submission from Gregory Beauregard : from typing import ParamSpec P = ParamSpec("P") print(P.args == P.args) # False print(P.kwargs == P.kwargs) # False ParamSpec args and kwargs are not equal to themselves; this can cause problems for unit tests and type introspect

[issue46655] typing.TypeAlias is not in the list of allowed plain _SpecialForm typeforms

2022-02-06 Thread Gregory Beauregard
Change by Gregory Beauregard : -- pull_requests: +29346 pull_request: https://github.com/python/cpython/pull/31175 ___ Python tracker <https://bugs.python.org/issue46

[issue46644] typing: remove callable() check from typing._type_check

2022-02-06 Thread Gregory Beauregard
Gregory Beauregard added the comment: I compiled your PR to run it and was testing in 3.10 as well, but I was testing in a file with from __future__ import annotations unintentionally. I retract the comment. It turns out `list[42]` is okay though, which I suppose is more relevant going

[issue46644] typing: remove callable() check from typing._type_check

2022-02-06 Thread Gregory Beauregard
Gregory Beauregard added the comment: I'm referring to within type annotations, where this code path isn't used: try a: List[42] This code path can show up in type aliases though. -- ___ Python tracker <https://bugs.python.org/issue46

[issue46644] typing: remove callable() check from typing._type_check

2022-02-06 Thread Gregory Beauregard
Gregory Beauregard added the comment: List[42] is already accepted, and your proposed patch does not change it to make it not accepted. The issue is _type_check is only called in a few particular locations; this is part of the technical reason I'm not very concerned about relaxing

[issue46642] typing: tested TypeVar instance subclass TypeError is incidental

2022-02-06 Thread Gregory Beauregard
Gregory Beauregard added the comment: The issue in real code I had in mind was internal to cpython: if we remove the callable() check from _type_check naively, this test starts to fail. Both of our proposed changes happen to not fail this check. Given your second example, would you prefer

[issue46655] typing.TypeAlias is not in the list of allowed plain _SpecialForm typeforms

2022-02-06 Thread Gregory Beauregard
Change by Gregory Beauregard : -- keywords: +patch pull_requests: +29331 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31156 ___ Python tracker <https://bugs.python.org/issu

[issue46655] typing.TypeAlias is not in the list of allowed plain _SpecialForm typeforms

2022-02-05 Thread Gregory Beauregard
Change by Gregory Beauregard : -- nosy: +kj ___ Python tracker <https://bugs.python.org/issue46655> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46655] typing.TypeAlias is not in the list of allowed plain _SpecialForm typeforms

2022-02-05 Thread Gregory Beauregard
Change by Gregory Beauregard : -- nosy: +Jelle Zijlstra ___ Python tracker <https://bugs.python.org/issue46655> ___ ___ Python-bugs-list mailing list Unsub

[issue46655] typing.TypeAlias is not in the list of allowed plain _SpecialForm typeforms

2022-02-05 Thread Gregory Beauregard
New submission from Gregory Beauregard : typing.TypeAlias is allowed to be bare, but it's not listed in the list of types in typing._type_check that are allowed to be bare. This means it's possible to reach the wrong error `TypeError: Plain typing.TypeAlias is not valid as type argument

[issue46644] typing: remove callable() check from typing._type_check

2022-02-05 Thread Gregory Beauregard
Change by Gregory Beauregard : -- keywords: +patch pull_requests: +29328 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31151 ___ Python tracker <https://bugs.python.org/issu

[issue46644] typing: remove callable() check from typing._type_check

2022-02-05 Thread Gregory Beauregard
Gregory Beauregard added the comment: I made a draft pull request where I went ahead and added a check to disallow tuple literals. This is basically already disallowed for types by restrictions on `__getitem__` because Union[typeform]->type needs to be different from Union[type,type]->

[issue46644] typing: remove callable() check from typing._type_check

2022-02-05 Thread Gregory Beauregard
Gregory Beauregard added the comment: Further questions: the msg argument in _type_check now wouldn't be used for anything! It was only used in the case where a type wasn't callable(). I think it should be removed. I'm also a bit negative on disallowing tuples in the case of e.g. Final

[issue46644] typing: remove callable() check from typing._type_check

2022-02-05 Thread Gregory Beauregard
Gregory Beauregard added the comment: Under the same failing int test cases before there were 2 more cases next to them that fail: with self.assertRaises(TypeError): ClassVar[int, str] with self.assertRaises(TypeError): Final[int, str] These fail because tuple literals

[issue46648] `test.test_urllib2.MiscTests.test_issue16464` started to fail

2022-02-05 Thread Gregory Beauregard
Change by Gregory Beauregard : -- nosy: +GBeauregard nosy_count: 2.0 -> 3.0 pull_requests: +29325 pull_request: https://github.com/python/cpython/pull/31148 ___ Python tracker <https://bugs.python.org/issu

[issue46642] typing: tested TypeVar instance subclass TypeError is incidental

2022-02-05 Thread Gregory Beauregard
Gregory Beauregard added the comment: Fixing this test unblocks bpo-46644 -- ___ Python tracker <https://bugs.python.org/issue46642> ___ ___ Python-bugs-list m

[issue46642] typing: tested TypeVar instance subclass TypeError is incidental

2022-02-05 Thread Gregory Beauregard
Change by Gregory Beauregard : -- keywords: +patch pull_requests: +29324 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31148 ___ Python tracker <https://bugs.python.org/issu

[issue46642] typing: tested TypeVar instance subclass TypeError is incidental

2022-02-05 Thread Gregory Beauregard
Gregory Beauregard added the comment: The reason this test passed before is a bit confusing. Run the following code standalone to see where the type(TypeVar('T'))(name, bases, namespace) check is coming from. ``` class TypeVar: def __init__(self, name, *constraints): # in actual

[issue46644] typing: remove callable() check from typing._type_check

2022-02-04 Thread Gregory Beauregard
Gregory Beauregard added the comment: In addition to the 10 tests failed in test_typing.py, one additional test fails in test_types.py with this change: https://github.com/python/cpython/blob/bf95ff91f2c1fc5a57190491f9ccdc63458b089e/Lib/test/test_types.py#L834-L838 and those are all

[issue46643] typing.Annotated cannot wrap typing.ParamSpec args/kwargs

2022-02-04 Thread Gregory Beauregard
Gregory Beauregard added the comment: We can also fix this with my proposal in bpo-46644. I'm okay with either fix (that or implementing __call__), or both. -- ___ Python tracker <https://bugs.python.org/issue46

[issue46644] typing: remove callable() check from typing._type_check

2022-02-04 Thread Gregory Beauregard
New submission from Gregory Beauregard : I propose removing the callable() check[1] from typing._type_check. This restriction is usually met in typeform instances by implementing a __call__ method that raises at runtime[2]. _type_check is called at runtime in a few disparate locations

[issue46643] typing.Annotated cannot wrap typing.ParamSpec args/kwargs

2022-02-04 Thread Gregory Beauregard
Change by Gregory Beauregard : -- nosy: +sobolevn ___ Python tracker <https://bugs.python.org/issue46643> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46643] typing.Annotated cannot wrap typing.ParamSpec args/kwargs

2022-02-04 Thread Gregory Beauregard
New submission from Gregory Beauregard : Consider the following. ``` import logging from typing import Annotated, Callable, ParamSpec, TypeVar T = TypeVar("T") P = ParamSpec("P") def add_logging(f: Callable[P, T]) -> Callable[P, T]: """A type-safe

[issue46642] typing: tested TypeVar instance subclass TypeError is incidental

2022-02-04 Thread Gregory Beauregard
New submission from Gregory Beauregard : https://github.com/python/cpython/blob/bf95ff91f2c1fc5a57190491f9ccdc63458b089e/Lib/test/test_typing.py#L227-L230 typing's testcases contain the following test to ensure instances of TypeVar cannot be subclassed: def test_cannot_subclass_vars(self

[issue46511] dataclasses: Allow typing.Annotated to wrap dataclasses-specific annotations

2022-01-28 Thread Gregory Beauregard
Gregory Beauregard added the comment: I had a few style, approach, and testing preference questions, but I decided they're probably best addressed in a code review so I went ahead and posted the PR. -- ___ Python tracker <https://bugs.python.

[issue46511] dataclasses: Allow typing.Annotated to wrap dataclasses-specific annotations

2022-01-28 Thread Gregory Beauregard
Change by Gregory Beauregard : -- keywords: +patch pull_requests: +29178 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30997 ___ Python tracker <https://bugs.python.org/issu

[issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

2022-01-28 Thread Gregory Beauregard
Change by Gregory Beauregard : -- keywords: +patch pull_requests: +29162 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30983 ___ Python tracker <https://bugs.python.org/issu

[issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

2022-01-27 Thread Gregory Beauregard
Gregory Beauregard added the comment: I think I miscommunicated my intent with sentence placement. I already posted the thoughts I referred to; they're just my concluding opinion on the technical merit of using get_type_hints in dataclasses to solve the Annotated problem: https

[issue46511] dataclasses: Allow typing.Annotated to wrap dataclasses-specific annotations

2022-01-27 Thread Gregory Beauregard
Gregory Beauregard added the comment: Hi Eric, to follow up on https://bugs.python.org/msg411943 I'm currently a bit negative on moving to get_type_hints, even though I got it working for the test suite. I think your worries with nesting are well placed, particularly with namespaces

[issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

2022-01-27 Thread Gregory Beauregard
Gregory Beauregard added the comment: It's acceptable to mypy, and pyright added support a few months ago when I made an issue and Eric Traut discovered this pattern in the wild too. Some of the other type checkers (pyre) still error I believe. My feeling is that since this has apparently

[issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

2022-01-27 Thread Gregory Beauregard
Gregory Beauregard added the comment: I'm drafting an implementation for the purpose of investigating performance right now; I will share when ready. -- ___ Python tracker <https://bugs.python.org/issue46

[issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

2022-01-27 Thread Gregory Beauregard
Change by Gregory Beauregard : -- nosy: +GBeauregard ___ Python tracker <https://bugs.python.org/issue46553> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

2022-01-27 Thread Gregory Beauregard
Change by Gregory Beauregard : -- type: -> behavior ___ Python tracker <https://bugs.python.org/issue46553> ___ ___ Python-bugs-list mailing list Unsubscrib

[issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

2022-01-27 Thread Gregory Beauregard
Change by Gregory Beauregard : -- nosy: +AlexWaygood, sobolevn -GBeauregard ___ Python tracker <https://bugs.python.org/issue46553> ___ ___ Python-bugs-list m

[issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

2022-01-27 Thread Gregory Beauregard
Gregory Beauregard added the comment: I think this is needed for moving dataclasses to using typing.py introspection tools to be viable. -- ___ Python tracker <https://bugs.python.org/issue46

[issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

2022-01-27 Thread Gregory Beauregard
New submission from Gregory Beauregard : ``` class C: a: "ClassVar" get_type_hints(C, globals()) # TypeError: Plain typing.ClassVar is not valid as type argument ``` A stringified lone ClassVar raises at runtime, but this pattern is tested for in dataclasses unit test

[issue46552] typing: get_type_hints can't handle stringified annotations with leading spaces

2022-01-27 Thread Gregory Beauregard
New submission from Gregory Beauregard : ``` class C: a: " ClassVar[int]" = 3 get_type_hints(C, globals()) # SyntaxError: Forward reference must be an expression -- got ' ClassVar[int]' ``` I discovered while investigating the viability of moving dataclasses.py to using t

[issue46539] typing: forward references don't understand special type forms

2022-01-26 Thread Gregory Beauregard
Gregory Beauregard added the comment: I did try the proposed patch in bpo-41370 and verified it didn't resolve the issue so I'm not certain they strictly overlap, but I also haven't had time to fully digest the underlying issues in bpo-41370 yet. I think it does have relevance for changes

[issue46539] typing: forward references don't understand special type forms

2022-01-26 Thread Gregory Beauregard
Gregory Beauregard added the comment: typo: the line is `g: Annotated["ClassVar[int]", (2, 5)] = 3` in the code sample. Somehow I left it at only `(` for the annotation instead of `(2,5)` -- ___ Python tracker <https://bugs.python.o

[issue46539] typing: forward references don't understand special type forms

2022-01-26 Thread Gregory Beauregard
Change by Gregory Beauregard : -- type: -> behavior ___ Python tracker <https://bugs.python.org/issue46539> ___ ___ Python-bugs-list mailing list Unsubscrib

[issue46539] typing: forward references don't understand special type forms

2022-01-26 Thread Gregory Beauregard
Change by Gregory Beauregard : -- keywords: +patch pull_requests: +29105 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30926 ___ Python tracker <https://bugs.python.org/issu

[issue46539] typing: forward references don't understand special type forms

2022-01-26 Thread Gregory Beauregard
New submission from Gregory Beauregard : Consider the following code on 3.11 main: ``` from typing import Annotated, ClassVar, get_type_hints class DC: a: ClassVar[int] = 3 b: ClassVar["int"] = 3 c: "ClassVar[int]" = 3 d: Annotated[ClassVar[int], (2, 5)]

[issue46511] dataclasses: Allow typing.Annotated to wrap dataclasses-specific annotations

2022-01-25 Thread Gregory Beauregard
Gregory Beauregard added the comment: Or rather, ^\s*(?:(?:\w+\s*\.)?\s*Annotated\s*\[)?(?:\s*(\w+)\s*\.)?\s*(\w+) -- ___ Python tracker <https://bugs.python.org/issue46

[issue46511] dataclasses: Allow typing.Annotated to wrap dataclasses-specific annotations

2022-01-25 Thread Gregory Beauregard
Gregory Beauregard added the comment: Thanks for getting back so quickly. Annotated is set up to be 'transparent' by default to `typing.get_type_hints` so in the case of using `typing.py` it can be made straightforward by chaining with `typing.get_origin`, I think. I don't see any

[issue46511] dataclasses: Allow typing.Annotated to wrap dataclasses-specific annotations

2022-01-25 Thread Gregory Beauregard
New submission from Gregory Beauregard : In https://bugs.python.org/issue46491 the typing runtime behavior was changed so that `Annotated[Classvar[...]]` is now valid at runtime in order to alleviate tension between typing and non-typing annotation space uses. dataclasses.py should likely

[issue46491] typing: allow Annotated in outermost scope

2022-01-24 Thread Gregory Beauregard
Change by Gregory Beauregard : -- keywords: +patch pull_requests: +29045 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30864 ___ Python tracker <https://bugs.python.org/issu

[issue46491] typing: allow Annotated in outermost scope

2022-01-23 Thread Gregory Beauregard
New submission from Gregory Beauregard : Currently, `typing.Annotated` (PEP 593) cannot be used at runtime with `typing.Final` and `typing.ClassVar` with `Annotated` on the outside: ``` from typing import Annotated, Final # TypeError: typing.Final[int] is not valid as type argument var

[issue45384] Accept Final as indicating ClassVar for dataclass

2021-10-14 Thread Gregory Beauregard
Gregory Beauregard added the comment: Hi Michael, Thanks for taking the time to look into this. I don't feel strongly enough about following the existing PEP wording to desire creating a situation where instance vars can't be marked Final if we can instead make a workaround with ClassVar

[issue45443] 'ThreadPoolExecutor' object has no attribute 'map'

2021-10-12 Thread Gregory Beauregard
Gregory Beauregard added the comment: I get no attribute error with this code in 3.9 or 3.10. -- nosy: +GBeauregard ___ Python tracker <https://bugs.python.org/issue45

[issue45384] Accept Final as indicating ClassVar for dataclass

2021-10-10 Thread Gregory Beauregard
Gregory Beauregard added the comment: Thanks for the feedback Carl. Your proposed nesting PEP change is not possible: ClassVar[Final[int]] isn't valid because Final[int] isn't a type. As far as I know this would need type intersections to be possible. I'm going to try sending a one-off

[issue45384] Accept Final as indicating ClassVar for dataclass

2021-10-09 Thread Gregory Beauregard
Gregory Beauregard added the comment: Yeah, I was just discussing this with someone in IRC, and I appreciate an example of it in the wild. I agree there's some wiggle room with what "initialized in a class body" means when it comes to dataclasses. I see several interpretations th

[issue45384] Accept Final as indicating ClassVar for dataclass

2021-10-09 Thread Gregory Beauregard
Gregory Beauregard added the comment: When I originally submitted the issue I hadn't finished going through all of the dataclasses code and it hadn't even occurred to me that it could be valid to use ClassVar with field(). I (wrongly) assumed this would always raise and that field() is only

[issue45384] Accept Final as indicating ClassVar for dataclass

2021-10-09 Thread Gregory Beauregard
Gregory Beauregard added the comment: Hi Eric, I've been shopping this idea around on the mailing list and haven't received any objections. Do you have any concerns? Can we handle Final with the same checks as ClassVar? Regarding potentially merging a change, I'm not sure where this falls

[issue45384] Accept Final as indicating ClassVar for dataclass

2021-10-05 Thread Gregory Beauregard
Change by Gregory Beauregard : -- type: enhancement -> behavior ___ Python tracker <https://bugs.python.org/issue45384> ___ ___ Python-bugs-list mai

[issue45384] Accept Final as indicating ClassVar for dataclass

2021-10-05 Thread Gregory Beauregard
New submission from Gregory Beauregard : PEP 591 for the Final Attribute states "Type checkers should infer a final attribute that is initialized in a class body as being a class variable. Variables should not be annotated with both ClassVar and Final." This is a bit of a typin