File tree Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change 15
15
Union ,
16
16
)
17
17
18
- from typing_extensions import Unpack
18
+ from typing_extensions import Self , Unpack
19
19
20
20
from basilisp .lang .obj import LispObject as _LispObject
21
21
from basilisp .lang .obj import PrintSettings , seq_lrepr
@@ -98,14 +98,11 @@ def meta(self) -> Optional["IPersistentMap"]:
98
98
raise NotImplementedError ()
99
99
100
100
101
- T_with_meta = TypeVar ("T_with_meta" , bound = "IWithMeta" )
102
-
103
-
104
101
class IWithMeta (IMeta ):
105
102
__slots__ = ()
106
103
107
104
@abstractmethod
108
- def with_meta (self : T_with_meta , meta : "Optional[IPersistentMap]" ) -> T_with_meta :
105
+ def with_meta (self , meta : "Optional[IPersistentMap]" ) -> Self :
109
106
raise NotImplementedError ()
110
107
111
108
@@ -122,6 +119,12 @@ def name(self) -> str:
122
119
def ns (self ) -> Optional [str ]:
123
120
raise NotImplementedError ()
124
121
122
+ @classmethod
123
+ @abstractmethod
124
+ def with_name (cls , name : str , ns : Optional [str ] = None ) -> Self :
125
+ """Create a new instance of this INamed with `name` and optional `ns`."""
126
+ raise NotImplementedError ()
127
+
125
128
126
129
ILispObject = _LispObject
127
130
Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ def name(self) -> str:
35
35
def ns (self ) -> Optional [str ]:
36
36
return self ._ns
37
37
38
+ @classmethod
39
+ def with_name (cls , name : str , ns : Optional [str ] = None ) -> "Keyword" :
40
+ return keyword (name , ns = ns )
41
+
38
42
def _lrepr (self , ** kwargs : Unpack [PrintSettings ]) -> str :
39
43
if self ._ns is not None :
40
44
return f":{ self ._ns } /{ self ._name } "
Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ def name(self) -> str:
47
47
def ns (self ) -> Optional [str ]:
48
48
return self ._ns
49
49
50
+ @classmethod
51
+ def with_name (cls , name : str , ns : Optional [str ] = None ) -> "Symbol" :
52
+ return Symbol (name , ns = ns )
53
+
50
54
@property
51
55
def meta (self ) -> Optional [IPersistentMap ]:
52
56
return self ._meta
You can’t perform that action at this time.
0 commit comments