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

Highlight typing hints in a different color than ordinary code. #183

Open
vistatest opened this issue May 16, 2019 · 8 comments
Open

Highlight typing hints in a different color than ordinary code. #183

vistatest opened this issue May 16, 2019 · 8 comments
Assignees

Comments

@vistatest
Copy link

@vistatest vistatest commented May 16, 2019

Typing hints are displayed in the same color as python variables and statements.
That looks somewhat confusing and makes it harder to see at once where is a typing hint, where a variable name is defined and where is an actual code.

E.g., the line below up to 'origin' is in the same color.

  remote: pygit2.Remote = gitrepo.remotes['origin']
@shadow-light
Copy link

@shadow-light shadow-light commented Jul 5, 2019

I agree. Would be nice to be able to apply a different color to type hints. I get the impression a lot of people like them to be just regular code. I'm fine with that as the default, but would be nice to add an extra label so some of us can for example make all type hints semi-transparent.

@cardoso-neto
Copy link

@cardoso-neto cardoso-neto commented Oct 6, 2019

There are also the type hints on function defs. And they very much deserve some highlighting.

def fun_func(
    big_param: Set[Tuple[int, int]],
    generic_param: List[T],
) -> Mapping[str, T]: ...
@cardoso-neto
Copy link

@cardoso-neto cardoso-neto commented Oct 19, 2019

Type annotations of the attributes of a dataclass need proper highlighting as well:

Number = Union[int, float]
@dataclass(frozen=True)
class SomeClass:
    foo: Generator[AnyStr, Number, None] = field(hash=False)
    bar: Iterable[T] = field(compare=False)
    amount: Number = -1
@cardoso-neto
Copy link

@cardoso-neto cardoso-neto commented Oct 27, 2019

When using generic types (typevar) on classes (inheriting from it), no highlighting appears.

V = TypeVar("V", FirstType, SomeOtherType)
E = TypeVar("E")

class StopIgnoringMe(Generic[V, E], ParentClass):
    pass

class NormalInheritance(ParentClass):
    pass
@vpetrovykh
Copy link
Member

@vpetrovykh vpetrovykh commented Oct 28, 2019

I'll see what I can do to highlight type hints better. I guess the starting point would be to at least give them all a scope of their own like meta.typehint.python.

@vpetrovykh vpetrovykh self-assigned this Oct 28, 2019
@dkrukouski
Copy link

@dkrukouski dkrukouski commented Feb 14, 2020

@vpetrovykh do you need help with the issue?

@cardoso-neto
Copy link

@cardoso-neto cardoso-neto commented Jun 5, 2020

It appears Github's highlighting decided that everything that starts with a capital letter deserves that same color.
I'm still inclined towards having separate scopes for typehints and for normal classes, so we can choose different colors.

@hassanselim0
Copy link

@hassanselim0 hassanselim0 commented Jul 9, 2020

I'd also like to have a separate scope for type hints.
I was writing some type hints in Django Models (so the fields show up as the real type and not the orm field type), but it made the code look ugly since the variable and the type hint and the field class name where all white, you couldn't easily see where the type hint ends and where the orm field class starts!
For now I settled for using # type comments instead since these do have their own scope and look better at the end of the line (I made the semi-transparent).

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

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.