@@ -79,7 +79,7 @@ Python is (also) an object oriented programming language. If it makes sense, pac
7979of the entity in your code, as instance attributes, property methods, or methods:
8080
8181``` python
82- from typing import Union, Dict, Text
82+ from typing import Union, Dict
8383
8484
8585class Record :
@@ -90,7 +90,7 @@ class User:
9090 info : str
9191
9292 @ property
93- def data (self ) -> Dict[Text, Text ]:
93+ def data (self ) -> Dict[str , str ]:
9494 return {}
9595
9696 def get_record (self ) -> Union[Record, None ]:
@@ -254,11 +254,10 @@ you are expecting a string as the argument.
254254** Good** :
255255
256256``` python
257- from typing import Text
258257import hashlib
259258
260259
261- def create_micro_brewery (name : Text = " Hipster Brew Co." ):
260+ def create_micro_brewery (name : str = " Hipster Brew Co." ):
262261 slug = hashlib.sha1(name.encode()).hexdigest()
263262 # etc.
264263```
@@ -304,9 +303,6 @@ menu = Menu(
304303** Also good**
305304
306305``` python
307- from typing import Text
308-
309-
310306class MenuConfig :
311307 """ A configuration for the Menu.
312308
@@ -316,9 +312,9 @@ class MenuConfig:
316312 button_text: The text for the button label.
317313 cancellable: Can it be cancelled?
318314 """
319- title: Text
320- body: Text
321- button_text: Text
315+ title: str
316+ body: str
317+ button_text: str
322318 cancellable: bool = False
323319
324320
@@ -376,7 +372,6 @@ create_menu(
376372** Even fancier**
377373
378374``` python
379- from typing import Text
380375from dataclasses import astuple, dataclass
381376
382377
@@ -390,9 +385,9 @@ class MenuConfig:
390385 button_text: The text for the button label.
391386 cancellable: Can it be cancelled?
392387 """
393- title: Text
394- body: Text
395- button_text: Text
388+ title: str
389+ body: str
390+ button_text: str
396391 cancellable: bool = False
397392
398393def create_menu (config : MenuConfig):
@@ -412,7 +407,7 @@ create_menu(
412407** Even fancier, Python3.8+ only**
413408
414409``` python
415- from typing import TypedDict, Text
410+ from typing import TypedDict
416411
417412
418413class MenuConfig (TypedDict ):
@@ -424,9 +419,9 @@ class MenuConfig(TypedDict):
424419 button_text: The text for the button label.
425420 cancellable: Can it be cancelled?
426421 """
427- title: Text
428- body: Text
429- button_text: Text
422+ title: str
423+ body: str
424+ button_text: str
430425 cancellable: bool
431426
432427
@@ -593,23 +588,23 @@ def parse_better_js_alternative(code: str) -> None:
593588** Good:**
594589
595590``` python
596- from typing import Tuple, List, Text, Dict
591+ from typing import Tuple, List, Dict
597592
598593
599594REGEXES : Tuple = (
600595 # ...
601596)
602597
603598
604- def parse_better_js_alternative (code : Text ) -> None :
599+ def parse_better_js_alternative (code : str ) -> None :
605600 tokens: List = tokenize(code)
606601 syntax_tree: List = parse(tokens)
607602
608603 for node in syntax_tree:
609604 pass
610605
611606
612- def tokenize (code : Text ) -> List:
607+ def tokenize (code : str ) -> List:
613608 statements = code.split()
614609 tokens: List[Dict] = []
615610 for regex in REGEXES :
@@ -638,12 +633,11 @@ paths based on a boolean.
638633** Bad:**
639634
640635``` python
641- from typing import Text
642636from tempfile import gettempdir
643637from pathlib import Path
644638
645639
646- def create_file (name : Text , temp : bool ) -> None :
640+ def create_file (name : str , temp : bool ) -> None :
647641 if temp:
648642 (Path(gettempdir()) / name).touch()
649643 else :
@@ -653,16 +647,15 @@ def create_file(name: Text, temp: bool) -> None:
653647** Good:**
654648
655649``` python
656- from typing import Text
657650from tempfile import gettempdir
658651from pathlib import Path
659652
660653
661- def create_file (name : Text ) -> None :
654+ def create_file (name : str ) -> None :
662655 Path(name).touch()
663656
664657
665- def create_temp_file (name : Text ) -> None :
658+ def create_temp_file (name : str ) -> None :
666659 (Path(gettempdir()) / name).touch()
667660```
668661
@@ -731,13 +724,12 @@ print(name, surname) # => Ryan McDermott
731724** Also good**
732725
733726``` python
734- from typing import Text
735727from dataclasses import dataclass
736728
737729
738730@dataclass
739731class Person :
740- name: Text
732+ name: str
741733
742734 @ property
743735 def name_as_first_and_last (self ) -> list :
@@ -797,12 +789,12 @@ updating multiple places any time you want to change one thing.
797789** Bad:**
798790
799791``` python
800- from typing import List, Text, Dict
792+ from typing import List, Dict
801793from dataclasses import dataclass
802794
803795@dataclass
804796class Developer :
805- def __init__ (self , experience : float , github_link : Text ) -> None :
797+ def __init__ (self , experience : float , github_link : str ) -> None :
806798 self ._experience = experience
807799 self ._github_link = github_link
808800
@@ -811,12 +803,12 @@ class Developer:
811803 return self ._experience
812804
813805 @ property
814- def github_link (self ) -> Text :
806+ def github_link (self ) -> str :
815807 return self ._github_link
816808
817809@dataclass
818810class Manager :
819- def __init__ (self , experience : float , github_link : Text ) -> None :
811+ def __init__ (self , experience : float , github_link : str ) -> None :
820812 self ._experience = experience
821813 self ._github_link = github_link
822814
@@ -825,7 +817,7 @@ class Manager:
825817 return self ._experience
826818
827819 @ property
828- def github_link (self ) -> Text :
820+ def github_link (self ) -> str :
829821 return self ._github_link
830822
831823
@@ -865,12 +857,12 @@ company_managers_list = get_manager_list(managers=company_managers)
865857** Good:**
866858
867859``` python
868- from typing import List, Text, Dict
860+ from typing import List, Dict
869861from dataclasses import dataclass
870862
871863@dataclass
872864class Employee :
873- def __init__ (self , experience : float , github_link : Text ) -> None :
865+ def __init__ (self , experience : float , github_link : str ) -> None :
874866 self ._experience = experience
875867 self ._github_link = github_link
876868
@@ -879,7 +871,7 @@ class Employee:
879871 return self ._experience
880872
881873 @ property
882- def github_link (self ) -> Text :
874+ def github_link (self ) -> str :
883875 return self ._github_link
884876
885877
0 commit comments