Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Self type #14041

Merged
merged 26 commits into from
Nov 15, 2022
Merged

Add support for Self type #14041

merged 26 commits into from
Nov 15, 2022

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Nov 8, 2022

Ref #12840
Fixes #11871
Fixes #14089

This is an alternative implementation to two existing PRs: #11666, #13133. This PR treats typing.Self as pure syntactic sugar, and transforms it into a type variable early during semantic analyzis.

This way we can re-use all the existing machinery and handled edge cases for self-types. The only new thing is self-type for attributes (as proposed in the PEP). This required handling in several places, since attribute access is duplicated in several places (see #7724), plus special forms (like NamedTuples and TypedDicts) and dataclasses plugin require additional care, since they use attribute annotations in special ways.

I don't copy all the existing tests for "old style" self-types, but only some common use cases, possible error conditions, and relevant new edge cases, such as e.g. special forms mentioned above, and implicit type variable binding for callable types.

cc @Gobot1234 (author of original PRs)

@Gobot1234
Copy link
Contributor

Gobot1234 commented Nov 8, 2022

Looks great. One test that's been missed is ClassVar[Self] which (I think) will currently fail (see https://github.com/python/mypy/pull/13133/files#diff-f782aad4853edceb67a88efe43d2869579d075a77b8e8dd2add91e818a9fa164R4048-R4051)

@ilevkivskyi
Copy link
Member Author

Yeah, I wasn't sure about ClassVar, and it is not covered in the PEP, so I just kept whatever semantics we have. It is probably easy to tweak, if people want to use it. I guess possible use case is various "singleton" or "canonical" instances, for example:

class Context:
    BACKGROUND: ClassVar[Self]
    ...

Context.BACKGROUND = Context()

@Gobot1234
Copy link
Contributor

Gobot1234 commented Nov 8, 2022

I know it's something pyright supports microsoft/pyright#2858 and it wasn't that hard to support in my fork

@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
Member Author

ilevkivskyi commented Nov 8, 2022

@Gobot1234 Hm, OK. But also looking at the original example in that issue I am not use we should allow Self in other unusual places (i.e. those not covered by Valid Locations for Self section). They work inconsistently in current version of this PR, I wasn't really careful (although they are probably not hard to support).

Also I will need to disable Self in metaclasses, as specified by the PEP.

@hauntsaninja Is there a way to get non-truncated output of mypy_primer? (if I don't want to run it locally :-))
EDIT: nvm, found it in the GH action logs.

@github-actions

This comment has been minimized.

mypy/semanal.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Left some comments (not a full review).

.. note::

This feature is available on Python 3.11 or newer. On older Python versions
you can import backported ``Self`` from latest ``typing_extensions``.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest replacing 'latest' with 'recent enough' since otherwise it go stale quickly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's misleading to start with "This feature is available on Python 3.11 or newer." Users will think they can't use Self before 3.11. I'd suggest saying:

Suggested change
you can import backported ``Self`` from latest ``typing_extensions``.
``Self`` can be imported from ``typing`` on Python 3.11 or higher, and also from
``typing_extensions`` on version 4.0.0 or higher.

(Ref: https://github.com/python/typing_extensions/blob/main/CHANGELOG.md#release-400-november-14-2021)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will make it more clear (or maybe just commit what Jelle proposed)

mypy/checkmember.py Outdated Show resolved Hide resolved
mypy/semanal_shared.py Outdated Show resolved Hide resolved
test-data/unit/check-dataclasses.test Show resolved Hide resolved

z: P
reveal_type(S().next) # N: Revealed type is "__main__.S"
reveal_type(z.next) # N: Revealed type is "__main__.P"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also test a subprotocol of P and accessing inherited property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added subprotocol test (didn't push yet). For inherited property there is testTypingSelfProperty in a different test file.

x: Self

class D(C[int]):
x: D
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we now have a class like this:

class E(D): pass

This should perhaps be an error (incompatible attribute), since the type of x is D in E, which could be considered incompatible with the definition in C. It looks like we don't have a similar check for methods, so it's okay to not generate an error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this looks wrong, but also may be not super easy to implement. Let's postpone this for now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding an xfail test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH it is unlikely it will be fixed accidentally, instead I will open a follow up issue, maybe at some point we will have energy to tighten this.

T = TypeVar("T")
class TD(TypedDict, Generic[T]):
val: T
next: Optional[Self]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we inherit a typed dict from TD?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypedDicts can't be inherited in a "normal" sense of this word, since we can't change item types, we can only add new items, so I usually call it extending.

Currently I eagerly expand Self in TypedDicts (and in NamedTuples), so in this case next will be still Optional[TD] in extended TypedDict. PEP doesn't say anything about TypedDicts and NamedTuples, and they are not really classes, so I just implemented whatever looked more natural (and also simpler to implement).

But actually thinking a bit more about this, maybe it would be better to implement them more like for classes, so it will point to extended dict. I am not sure yet.

[file m.py]
import lib
class D(lib.C):
def meth(self, other: int) -> D: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about switching a method to use a self type in a fine-grained increment? All the call sites to the method (including subclasses) should be updated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about switching a method to use a self type in a fine-grained increment?

This is what I am doing, see [file lib.py.2]. But anyway, I will use a method call to verify update (in a different module), instead of Liskov check.

test-data/unit/check-selftype.test Show resolved Hide resolved
docs/source/generics.rst Show resolved Hide resolved
@ilevkivskyi
Copy link
Member Author

@JukkaL Thanks for comments! I addressed almost all of them.

I am not sure what to do with the uses in TypedDicts (and also in NamedTuples). Btw PEP actually prohibits Self in type aliases because it is ambiguous. Maybe we should also prohibit Self in TypedDicts and NamedTuples as well? They also can be quite ambiguous, especially when using call syntax, and even more when using call syntax inside another class.

@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
Member Author

OK, I have addressed all CR, and I am happy with mypy_primer. I also added two follow up issues:

If there will be no more comments, I will merge this in next couple days.

ikonst added a commit to ikonst/mypy that referenced this pull request Nov 14, 2022
ikonst added a commit to ikonst/mypy that referenced this pull request Nov 14, 2022
ikonst added a commit to ikonst/mypy that referenced this pull request Nov 14, 2022
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/dependencies/data.py:87: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/dependencies/data.py:87: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/dependencies/data.py:93: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/dependencies/data.py:93: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:228: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:228: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:310: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:310: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:921: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:921: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:925: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:925: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:929: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:929: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:1350: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:1350: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:1692: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:1692: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:1789: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:1789: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2054: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2054: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2058: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2058: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2127: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2127: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2178: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2178: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2226: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2226: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2274: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2274: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2407: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2407: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2411: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2411: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2415: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2415: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2425: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2425: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2440: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2440: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2455: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2455: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2475: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2475: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2603: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2603: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2658: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2658: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2673: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2673: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2779: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2779: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2794: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2794: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2835: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2835: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2839: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2839: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2843: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2843: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2925: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2925: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2940: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2940: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:2961: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:2961: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3001: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3001: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3016: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3016: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3150: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3150: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3167: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3167: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3182: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3182: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3226: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3226: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3241: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3241: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3292: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3292: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3307: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3307: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3358: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3358: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3375: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3375: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3424: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3424: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:3428: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:3428: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4073: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4073: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4090: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4090: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4120: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4120: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4143: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4143: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4161: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4161: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4222: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4222: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4281: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4281: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4303: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4303: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4499: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4499: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4552: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4552: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4622: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4622: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4674: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4674: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4733: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4733: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4765: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4765: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4785: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4785: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/abc.py:4817: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/abc.py:4817: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:115: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:115: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:119: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:119: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:124: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:124: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:153: error: Returning Any from function declared to return Self?  [no-any-return]
- tanjun/hooks.py:160: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:160: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:165: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:165: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:187: error: Returning Any from function declared to return Self?  [no-any-return]
- tanjun/hooks.py:194: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:194: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:199: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:199: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:218: error: Returning Any from function declared to return Self?  [no-any-return]
- tanjun/hooks.py:225: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:225: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:230: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:230: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:249: error: Returning Any from function declared to return Self?  [no-any-return]
- tanjun/hooks.py:256: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:256: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:261: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/hooks.py:261: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/hooks.py:280: error: Returning Any from function declared to return Self?  [no-any-return]
- tanjun/dependencies/locales.py:145: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/dependencies/locales.py:145: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/context/base.py:119: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/context/base.py:119: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/context/base.py:130: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/context/base.py:130: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:323: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:323: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:340: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:340: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:344: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:344: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:352: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:352: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:422: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:422: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:448: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:448: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:468: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:468: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:489: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:489: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:494: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:494: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:510: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:510: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:526: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:526: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:542: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:542: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:558: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:558: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:576: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:576: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:618: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:618: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:743: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:743: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:773: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:773: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:852: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:852: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:866: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:866: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:889: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:889: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:903: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:903: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:928: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:928: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:970: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:970: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:997: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:997: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:1013: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:1013: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:1037: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:1037: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:1085: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:1085: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:1133: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:1133: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:1155: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:1155: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:1349: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:1349: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/components.py:1368: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/components.py:1368: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/dependencies/reloaders.py:195: error: Self? has no attribute "add_client_callback"  [attr-defined]
- tanjun/dependencies/reloaders.py:202: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/dependencies/reloaders.py:202: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/dependencies/reloaders.py:216: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/dependencies/reloaders.py:216: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/dependencies/reloaders.py:241: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/dependencies/reloaders.py:241: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/dependencies/reloaders.py:256: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/dependencies/reloaders.py:256: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/context/slash.py:400: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/context/slash.py:400: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/context/slash.py:421: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/context/slash.py:421: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/context/slash.py:1040: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/context/slash.py:1040: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/context/message.py:180: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/context/message.py:180: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/context/message.py:195: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/context/message.py:195: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/context/message.py:201: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/context/message.py:201: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/context/message.py:207: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/context/message.py:207: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:83: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:83: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:296: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:296: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:310: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:310: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:326: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:326: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:519: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:519: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:537: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:537: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:667: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:667: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:686: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:686: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:739: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:739: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:758: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:758: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:777: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:777: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:1053: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:1053: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:1147: error: Variable "typing_extensions.Self" is not valid as a type  [valid-type]
- tanjun/schedules.py:1147: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- tanjun/schedules.py:1165: erro

... (truncated 955 lines) ...

@ilevkivskyi
Copy link
Member Author

It looks like there are no more comments, I will be merging this later today.

@ilevkivskyi ilevkivskyi merged commit 77dd4b4 into python:master Nov 15, 2022
@ilevkivskyi ilevkivskyi deleted the self-type branch November 15, 2022 22:03
jvosk added a commit to jvosk/AoC2022 that referenced this pull request Dec 8, 2022
- removed YAGNI code (`FSO` class)
- improved input parsing/filesystem building fn
- removed unneeded overhead function definitions (Filesystem.tail, Directory.add, Directory.dir_sizes)

In theory, the `# type: ignore` hints (for `mypy` typechecking) should be able to be removed once python/mypy#14041 is integrated into the next release.
@12rambau 12rambau mentioned this pull request Dec 27, 2022
3 tasks
@patrick91
Copy link
Contributor

@ilevkivskyi this hasn't been release yet, right?

@hauntsaninja
Copy link
Collaborator

No, not yet

@henryiii
Copy link
Contributor

henryiii commented Feb 6, 2023

Now it has. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message for typing_extensions.Self is confusing support pep 673 Self type
9 participants