KotlinIsland / KotlinIsland/basedtyping

a `classonlymethod` decorator

Open
#108 1 comment 0 reactions 0 assignees View on GitHub
good first issue
Dominant language
Python
Stars
12
Forks
2
PR merge metrics
No merged PRs in 30d

Description

```py
class A:
@classmethod
def a(cls): ...
@classonlymethod
def b(cls): ...
A.a() # ok
A.b() # ok
A().a() # ok
A().b() # not ok (😞)
```
The reasoning is that the `classmethod` decorator is often used for alternative constructors, so using it on instances would be a mistaken usage.

### implementation
We could attempt a vanilla implementation using descriptors, otherwise a simple alias
```py
if not TYPE_CHECKING:
classonlymethod = classmethod
else:
class classonlymethod(classmethod): # or something
...
```

Contributor guide

No contributing guide indexed for this repository

Research direction

No file, test, or entry point is named in the issue. Start by locating the runtime decorator definitions and existing typing tests, then use the A example to verify class access remains valid while instance access is rejected. Done means the runtime and type-checking behavior for classonlymethod is agreed and covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.