Skip to content

Self issue with PySide (fix proposal) #619

Open
@noamgot

Description

@noamgot

Hello
While the issue I describe is a very weird phenomenon that's not directly related to typing_extensions, I would like to propose a solution that might be able to solve this.

Note: this is an issue related to python <=3.10

Minimal reproducable example

import typing

print(hasattr(typing, "Self"))

import PySide6 # noqa

print(hasattr(typing, "Self"))

This prints:

False
True

In other words, PySide6 manipulates python's built-in typing module.

Observation

Examining typing_extension.py, I found this section

if hasattr(typing, "Self"): # 3.11+
Self = typing.Self
else:
@_SpecialForm
def Self(self, params):

Proposal

Would it make sense to check sys.version_info instead of checking the existance of Self attribute?
This is already done in several places, e.g.:

if sys.version_info >= (3, 11):
from typing import Any
else:
class _AnyMeta(type):

IMHO it looks like a more robust solution (that can solve this specific problem)

I would love to hear your thoughts. I'd be happy to open a PR if needed.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions