kopia lustrzana https://github.com/inkstitch/inkstitch
				
				
				
			Monkeytype help
							rodzic
							
								
									90f2fe73fc
								
							
						
					
					
						commit
						09da8964d2
					
				| 
						 | 
				
			
			@ -39,12 +39,21 @@ Type annotations also allow us to use the typechecker [Mypy](https://mypy.readth
 | 
			
		|||
A great reference for how to use annotations is the [Mypy cheat sheet](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html).
 | 
			
		||||
It covers most of the common uses and patterns.
 | 
			
		||||
[Mypy's Common Issues page](https://mypy.readthedocs.io/en/stable/common_issues.html) is also useful for understanding the common pitfalls with type-checking you may encounter.
 | 
			
		||||
Notably, Mypy does not perform type-checking on functions that don't have type annotations, but as we introduce new code with annotations we'll have better coverage as time goes on.
 | 
			
		||||
 | 
			
		||||
You can run Mypy against your changes yourself simply by [installing Mypy](https://mypy.readthedocs.io/en/stable/getting_started.html#installing-and-running-mypy) running `mypy` in the project root.
 | 
			
		||||
The project's mypy.ini file sets all of the relevant configuration, so no other arguments are needed.
 | 
			
		||||
Mypy is also run as part of this project's builds on Github.
 | 
			
		||||
Errors that Mypy picks up won't cause your build to fail, but will appear on Pull Requests so both you and reviewers can see the potential issues.
 | 
			
		||||
 | 
			
		||||
Much of our code, especially older code, lacks type annotations.
 | 
			
		||||
If you want to add type annotations to older code, or learn what types are used in a part of the codebase without type annotations, you my find [MonkeyType](https://monkeytype.readthedocs.io/en/stable/) useful.
 | 
			
		||||
You can easily have MonkeyType collect type information from Ink/Stitch in a similar way to how you can use one of several profilers with Ink/Stitch.
 | 
			
		||||
Simply copy `DEBUG_template.toml` to `DEBUG.toml`, and uncomment lines so that the `profiler_type = "monkeytype"`
 | 
			
		||||
and `profile_enable = True` options are set.
 | 
			
		||||
After running Ink/Stitch command, a window will pop up telling you how to run Monkeytype and use your newly-collected type information.
 | 
			
		||||
Multiple command runs will all add to the type information database.
 | 
			
		||||
 | 
			
		||||
Guidance and Comments
 | 
			
		||||
=====================
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -295,11 +295,12 @@ def with_monkeytype(extension, remaining_args, profile_file_path: Path) -> None:
 | 
			
		|||
 | 
			
		||||
    # Monkeytype will use these environment variables for the db path and to filter the modules respectively.
 | 
			
		||||
    # This is easier than using monkeytype's actual config API, anyway.
 | 
			
		||||
    os.environ["MT_DB_PATH"] = str(profile_file_path)
 | 
			
		||||
    dbpath = profile_file_path.with_suffix('.sqlite')
 | 
			
		||||
    os.environ["MT_DB_PATH"] = str(dbpath)
 | 
			
		||||
    os.environ["MONKEYTYPE_TRACE_MODULES"] = str(Path(__file__).parents[2].name)
 | 
			
		||||
 | 
			
		||||
    with monkeytype.trace():
 | 
			
		||||
        extension.run(args=remaining_args)
 | 
			
		||||
 | 
			
		||||
    print(f"Profiler: monkeytype, db written to '{profile_file_path}'.\n\
 | 
			
		||||
          Run 'MT_DB_PATH={profile_file_path} monkeytype ...' from the inkstitch repo directory.", file=sys.stderr)
 | 
			
		||||
    print(f"Profiler: monkeytype, db written to '{dbpath}'.\n\
 | 
			
		||||
          Run 'MT_DB_PATH={dbpath} monkeytype ...' from the inkstitch repo directory.", file=sys.stderr)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue