{"text_format":"3","workbook":"xlsx","n_sheets":2,"sheets":["All Guidance (Extracted)","Section 5 (First Draft)"],"not_rendered":{"defined_names":2},"read":"whole","date_system":"1900"}

{"sheet":"All Guidance (Extracted)","index":0,"n_rows":145,"n_cols":4,"rows_kept":145,"merged":[[1,0,5,0],[1,1,5,1],[6,0,8,0],[6,1,8,1],[9,0,12,0],[9,1,12,1],[13,0,14,0],[13,1,14,1],[15,0,18,0],[15,1,18,1],[19,0,21,0],[19,1,21,1],[22,0,27,0],[22,1,27,1],[28,0,30,0],[28,1,30,1],[31,0,33,0],[31,1,33,1],[34,0,37,0],[34,1,37,1],[39,0,40,0],[39,1,40,1],[41,0,43,0],[41,1,43,1],[44,0,45,0],[44,1,45,1],[46,0,47,0],[46,1,47,1],[48,0,49,0],[48,1,49,1],[50,0,52,0],[50,1,52,1],[53,0,54,0],[53,1,54,1],[55,0,56,0],[55,1,56,1],[58,0,60,0],[58,1,60,1],[61,0,62,0],[61,1,62,1],[63,0,64,0],[63,1,64,1],[65,0,66,0],[65,1,66,1],[67,0,68,0],[67,1,68,1],[70,0,71,0],[70,1,71,1],[72,0,74,0],[72,1,74,1],[75,0,77,0],[75,1,77,1],[78,0,79,0],[78,1,79,1],[80,0,82,0],[80,1,82,1],[83,0,84,0],[83,1,84,1],[85,0,92,0],[85,1,92,1],[93,0,95,0],[93,1,95,1],[96,0,103,0],[96,1,103,1],[104,0,111,0],[104,1,111,1],[112,0,115,0],[112,1,115,1],[116,0,118,0],[116,1,118,1],[119,0,133,0],[119,1,133,1],[134,0,137,0],[134,1,137,1],[138,0,141,0],[138,1,141,1],[142,0,144,0],[142,1,144,1]]}
["No.","Section Name","Top Guidance (Highlighted)\nBased on file:\nISO-IECJTC1-SC22-WG23_N0961-tr24772-4-draft-python-after-meeting-20200615.docx\n(General/Python-Specific)","Priority"]
[6.2,"Type System [IHN]","Use static type checkers to detect typing errors. The Python community provides static type checkers"]
[null,null,"Pay special attention to issues of magnitude and precision when using mixed type expressions"]
[null,null,"Be aware of the consequences of shared references"]
[null,null,"Be aware of the conversion from simple to complex"]
[null,null,"Do not check for specific types of objects unless there is good justification, for example, when calling an extension that requires a specific type"]
[6.3,"Bit Representations [STR]","Avoid bit operations on signed operands"]
[null,null,"Localize and document the code associated with explicit manipulation of bits and bit fields"]
[null,null,"Keep in mind that using a very large integer will have a negative effect on performance"]
[6.4,"Floating-point Arithmetic [PLF]","Use floating-point arithmetic only when absolutely needed"]
[null,null,"Do not use floating-point types when fixed-point types, integers or Booleans suffice"]
[null,null,"Be aware that precision is lost for some real numbers (that is, floating-point is an approximation with limited precision for some numbers)"]
[null,null,"Code algorithms to account for the fact that results can vary slightly by implementation"]
[6.5,"Enumerator Issues [CCB]","Be aware that assigning a list of names to integers is not safe since the variable can be bound to another object at any time."]
[null,null,"Use the new enum module for better reliability and safety"]
[6.6,"Conversion Errors [FLC]","Though there is generally no need to be concerned with an integer getting too large (rollover) or small, be aware that iterating or performing arithmetic with very large positive or small (negative) integers will hurt performance"]
[null,null,"Be aware of the potential consequences of precision loss when converting from floating point to integer"]
[null,null,"Design coding strategies that allow the distinction of semantically incompatible types"]
[null,null,"Use or develop units libraries to handle conversions between differing unit-based systems"]
[6.15,"Arithmetic Wrap-around Error [FIF]","Be cognizant that most arithmetic and bit manipulation operations on non-integers have the potential for undetected wrap-around errors."]
[null,null,"Avoid using floating point or decimal variables for loop control but if you must use these types then bound the loop structures so as to not exceed the maximum or minimum possible values for the loop control variables."]
[null,null,"Test the implementation that you are using to see if exceptions are raised for floating point operations and if they are then use exception handling to catch and handle wrap-around errors."]
[6.17,"Choice of Clear Names [NAI]","Avoid names that differ only by case unless necessary to the logic of the usage, and in such cases document the usage"]
[null,null,"Adhere to Python’s naming conventions"]
[null,null,"Do not use overly long names"]
[null,null,"Use names that are not similar (especially in the use of upper and lower case) to other names"]
[null,null,"Use meaningful names"]
[null,null,"Use names that are clear and visually unambiguous because the compiler cannot assist in detecting names that appear similar but are different"]
[6.18,"Dead Store [WXQ]","Avoid rebinding except where it adds identifiable benefit"]
[null,null,"Ensure that when examining code that you consider that a variable can be bound (or rebound) to another object (of same or different type) at any time"]
[null,null,"Consider using ResourceWarning to detect implicit reclamation of resources"]
[{"v":6.2,"d":"6.20"},"Identifier Name Reuse [YOW]","Do not use identical names unless necessary to reference the correct object"]
[null,null,"Avoid the use of the global and nonlocal specifications because they are generally a bad programming practice for reasons beyond the scope of this annex and because their bypassing of standard scoping rules make the code harder to understand"]
[null,null,"Use qualification when necessary to ensure that the correct variable is referenced"]
[6.21,"Namespace Issues [BJL]","Use absolute  imports, where the full path is specified, in preference to relative imports."]
[null,null,"When using the import statement, rather than use the from X import * form (which imports all of module X’s attributes into the importing program’s namespace), instead explicitly name the attributes that you want to import (for example, from X import a, b, c) so that variables, functions and classes are not inadvertently overlaid."]
[null,null,"Avoid implicit references to global values from within functions to make code clearer. In order to update globals within a function or class, place the global statement at the beginning of the function definition and list the variables so it is clearer to the reader which variables are local and which are global (for example, global a, b, c). "]
[null,null,"When interfacing with external systems or other objects where the declaration order of class members is relevant, use __prepare__ to obtain the desired order for class member creation.  "]
[6.22,"Initialization of Variables [LAV]","Ensure that it is not logically possible to reach a reference to a variable before it is assigned to avoid the occurrence of a runtime error"]
[6.24,"Side-effects and Order of Evaluation of Operands [SAM]","Be aware of Python’s short-circuiting behaviour when expressions with side effects are used on the right side of a Boolean expression"]
[null,null,"Use the assert statement during the debugging phase of code development to help eliminate undesired conditions from occurring."]
[6.25,"Likely Incorrect Expression [KOA]","Add parentheses after a function call in order to invoke the function."]
[null,null,"Keep in mind that any function that changes a mutable object in place returns a None object – not the changed object since there is no need to return an object because the object has been changed by the function."]
[null,null,"Be sure to use an await statement for async coroutines and ensure that all routines are nonblocking"]
[6.26,"Dead and Deactivated Code [XYQ]","Import just the attributes that are required by using the from statement to avoid adding dead code"]
[null,null,"Be aware that subsequent imports have no effect; use the reload statement instead of import if a fresh copy of the module is desired"]
[6.28,"Demarcation of Control Flow [EOJ]","Use only spaces or tabs, not both, to indent to demark control flow"]
[null,null,"Note: Python 3.0+ will refuse to compile code that uses a mixture of tabs and spaces for indentation"]
[6.29,"Loop Control Variables [TEX]","Be careful to only modify variables involved in loop control in ways that are easily understood and in ways that cannot lead to a premature exit or an endless loop"]
[null,null,"When using the for statement to iterate through a mutable object, do not add or delete members because it could have unexpected results"]
[{"v":6.3,"d":"6.30"},"Off-by-one Error [XZH]","Be aware of Python’s indexing from zero and code accordingly"]
[null,null,"Use the for statement to execute over whole constructs in preference to loops that index individual elements"]
[null,null,"Use the enumerate() builtin when both container elements and their position within the iteration sequence are required"]
[6.31,"Structured Programming [EWD]","Use “with” statements and context managers to enclose regions, and use them to invoke code which may create exceptions"]
[null,null,"Use the break statement judiciously to exit from control structures and show statically that it behaves correctly in all contexts"]
[6.32,"Passing Parameters and Return Values [CSJ]","Create copies of mutable objects before calling a function if changes are not wanted to mutable arguments"]
[null,null,"Uses types.MappingProxy or collections.ChainMap to provide read-only views of mappings without the cost of making a copy"]
[6.33,"Dangling References to Stack Frames [DCM]","Avoid using ctypes when calling C code from within Python and use cffi (C Foreign Function Interface) instead"]
[6.34,"Subprogram Signature Mismatch [OTR]","Avoid using ctypes when calling C code from within Python and use cffi (C Foreign Function Interface) instead since it is more streamlined and safer"]
[null,null,"Document the expected types of the formal parameters (type hints) and apply static analysis tools that check the program for correct usage of types"]
[null,null,"Use type membership tests to prevent runtime exceptions due to unexpected parameter types"]
[6.36,"Ignored Error Status and Unhandled Exceptions [OYB]","Use Python’s exception handling with care in order to not catch errors that are intended for other exception handlers, i.e. always catch named exceptions"]
[null,null,"Use exception handling, but directed to specific tolerable exceptions, to ensure that crucial processes can continue to run even after certain exceptions are raised"]
[6.38,"Deep vs. Shallow Copying [YAN]","Use the “slice” operator [:] or container copy() methods to force a copy up to one nested level.    Note: x = y[:] or x = y.copy() copies the complete next level, but leaves deeper levels, such as sublists shared."]
[null,null,"To force deep copies at all levels of a variable, use the “copy.deepcopy” standard library function. "]
[6.39,"Memory Leaks and Heap Fragmentation [XYL]","Release each object when it is no longer required. "]
[null,null,"Use context managers to explicitly release large memory buffers that are no longer needed"]
[6.41,"Inheritance [RIP]","Inherit only from trusted classes"]
[null,null,"Use Python’s built-in documentation (such as docstrings) to obtain information about a class’ methods before inheriting from the class"]
[6.42,"Violations of the Liskov Substitution  Principle or the Contract Model  [BLP]","Use static analysis tools, either commercial or provided by the Python community to detect Liskov substitution violations"]
[6.45,"Extra Intrinsics [LRM]","Do not override built-in “intrinsics”"]
[null,null,"If it is necessary to override an intrinsic, document the case and show that it behaves as documented and that it preserves all the properties of the built-in intrinsic"]
[6.47,"Inter-language Calling [DJS]","Do not write Python extension modules by hand, as doing so is error-prone, and highly likely to lead to reference counting errors, memory leaks, dangling pointers, out-of-bounds memory accesses, and similar problems"]
[null,null,"Python maintainers recommend that developers use existing libraries and tools that automatically generate the Python interface code from simpler descriptions of intent, such as those covered in https://packaging.python.org/guides/packaging-binary-extensions/  such as Cython, cffi, and SWIG."]
[null,null,"Where available, use existing interface libraries that bridge between Python and the extension module language, for example, PyO3 for Rust, pybind11 for C++. "]
[6.48,"Dynamically-linked Code and Self-modifying Code [NYY]","Avoid using exec or eval and never use these with untrusted code"]
[null,null,"Be careful when using Guerrilla patching to ensure that all uses of the patched classes and/or modules continue to function as expected; conversely, be aware of any code that patches classes and/or modules that your code is using to avoid unexpected results"]
[null,null,"Ensure that the file path and files being imported are from trusted sources"]
[6.49,"Library Signature [NSQ]","Use only trusted modules as extensions"]
[null,null,"If coding an extension, utilize Python’s extension API to ensure a correct signature match"]
[6.51,"Pre-processor Directives [NMP]","During development, avoid using the default entry points (python.exe on Windows, and pythonX.Y on other platforms) since these are executable from the command line and do not have hooks enabled by default. Consider using a modified entry point that restricts the use of optional arguments since this will reduce the chance of unintentional code from being executed. The entry point should not use any unprotected settings from the working environment. "]
[null,null,"Consider logging all predetermined events and backing them up to a non-local file so that an attacker cannot delete them. All events should be recorded prior to abort operations so that full traceability is preserved.    "]
[null,null,"Consider using DeviceGuard and the open_for_import hook to validate the signatures of all files in the Python application. "]
[6.53,"Provision of Inherently Unsafe Operations [SKL]","Use only trusted modules"]
[null,null,"Avoid the use of the exec and eval functions"]
[6.54,"Obscure Language Features [BRS]","Ensure that a function is defined before attempting to call it"]
[null,null,"Be aware that a function is defined dynamically so its composition and operation may vary due to variations in the flow of control within the defining program"]
[null,null,"Be aware of when a variable is local versus global"]
[null,null,"Do not use mutable objects as default values for arguments in a function definition unless you absolutely need to and you understand the effect"]
[null,null,"Be aware that when using the += operator on mutable objects the operation is done in place"]
[null,null,"Be cognizant that assignments to objects, mutable and immutable, always create a new object"]
[null,null,"Understand the difference between equivalence and equality and code accordingly"]
[null,null,"Ensure that the file path used to locate a persisted file or DBMS is correct and never ingest objects from an untrusted source."]
[6.55,"Unspecified Behaviour [BQF]","Do not rely on the content of error messages – use exception objects instead"]
[null,null,"When persisting object using pickling use exception handling to cleanup partially written files"]
[null,null,"Do not depend on the way Python may or may not optimize object references for small integer and string objects because it may vary for environments or even for releases in the same environment"]
[6.56,"Undefined Behaviour [EWF]","Understand the difference between testing for equivalence (for example, ==) and equality (for example, is) and do not depend on object identity tests to pass or fail when the variables reference immutable objects"]
[null,null,"Do not depend on the sequence of keys in a dictionary to be consistent across implementations, or even between multiple executions with the same implementation,  in versions prior to Python 3.7"]
[null,null,"When launching parallel tasks do not raise a BaseException subclass in a callable in the Future class"]
[null,null,"Do not modify the dictionary object returned by a vars call"]
[null,null,"Do not use form feed characters for indentation"]
[null,null,"Consider using the id function to test for object equality"]
[null,null,"Do not try to use the catch_warnings function to suppress warning messages when using more than one thread"]
[null,null,"Do not inspect or change the content of a list when sorting a list using the sort() method"]
[6.57,"Implementation–defined Behaviour [FAB]","Always use either spaces or tabs (but not both) for indentations"]
[null,null,"Consider using the -tt command line option to raise an IndentationError in Python 2.7 (3.x will do this automatically)"]
[null,null,"Consider using a text editor to find and make consistent, the use of tabs and spaces for indentation"]
[null,null,"Either avoid logic that depends on byte order or use the sys.byteorder variable and write the logic to account for byte order dependent on its value ('little' or 'big')"]
[null,null,"Use zero (the default exit code for Python) for successful execution and consider adding logic to vary the exit code according to the platform as obtained from sys.platform (such as, 'win32', 'darwin', or other)"]
[null,null,"Interrogate the sys.float.info system variable to obtain platform specific attributes and code according to those constraints"]
[null,null,"Call  the sys.getfilesystemcoding() function to return the name of the encoding system used"]
[null,null,"When high performance is dependent on knowing the range of integer numbers that can be used without degrading performance use the sys.int_info struct sequence to obtain the number of bits per digit (bits_per_digit) and the number of bytes used to represent a digit (sizeof_digit)"]
[6.59,"Concurrency – Activation [CGA]","For any thread that has already been started, ensure that additional starts on that same thread are not attempted. Multiple attempts to start any single thread object will raise a runtime error"]
[null,null,"If a thread is unable to be created and an exception is thrown, always handle the exception"]
[null,null,"For any process that has already been started, ensure that additional starts on that same process are not attempted. Multiple attempts to start any process object will raise a runtime error"]
[null,null,"Starting Async IO tasks using the asyncio module can only occur on a thread that is not running. During development, it is recommended to run the Async IO code in debug mode. This will help detect never-awaited coroutines, non-threadsafe Async IO APIs, excessive execution times for I/O and callback functions, and never-retrieved exceptions.  To reduce the chance of excessive delays, all concurrent Async IO operations need to be performed on non-blocking code"]
[{"v":6.6,"d":"6.60"},"Concurrency – Directed termination [CGT]","Avoid killing threads except as an extreme measure"]
[null,null,"If necessary, the preferred method for killing a thread is from within the thread itself using a watchdog message queue or global variable that signals the thread to terminate itself. This will enable the thread to perform proper cleanup and eliminate deadlocks"]
[null,null,"Use care when terminating processes since finally clauses will not be executed, and descendant processes will not be terminated.  Design the code to be fail-safe since terminating a process may corrupt data associated with pipes and queues"]
[6.61,"Concurrent Data Access [CGX]","Use join() to ensure that the calling thread is blocked until all joined threads have either terminated normally, thrown an exception, or timed out (if implemented)"]
[null,null,"Ensure that join() is not used on a thread before it is started since this will throw an exception"]
[null,null,"Verify that the opportunity does not exist for any thread to perform multiple joins since this would result in a deadlock condition"]
[null,null,"Ensure that no thread is waiting on daemon threads to complete since these threads are always running"]
[null,null,"Performing a join() on a daemon thread will result in a deadlock condition and it is recommended to use a join() on the message queue instead"]
[null,null,"If two or more items need to occur sequentially, ensure that they are ordered correctly and reside in the same thread, or provide synchronization between the two items in different threads"]
[null,null,"When using multiple processes, avoid using global variables and consider using the multiprocessing.Queue() function to share data between processes"]
[null,null,"When using multiple threads, avoid using global variables and consider using the queue.Queue() function to share data between threads"]
[null,null,"When using multiple threads, verify that no unprotected data is used directly by more than one thread"]
[null,null,"When using multiple threads, consider using the ThreadPoolExecutor within the concurrent.futures module to help maintain and control the number of threads being implemented"]
[null,null,"When using multiple threads, check for race conditions and deadlocks by using fuzzing techniques during development"]
[null,null,"If shared variables must be used in multithreaded applications, use model checking or equivalent methodologies to prove the absence of race conditions"]
[null,null,"For all new applications that require concurrency, consider using Async IO instead of threads or processes whenever possible. The reliability, speed, and maintainability of Async IO code is superior even though there is a steep learning curve"]
[null,null,"When converting existing code to Async IO, yield and await statements must be added to the code"]
[null,null,"When using Async IO, all tasks must be non-blocking and use Async IO calls from an event loop. Locks and other synchronization techniques are usually not needed when implementing Async IO"]
[6.62,"Concurrency – Premature Termination [CGS]","Use the finally keyword for each thread method that notifies a higher-level construct of the termination so that corrective action can be taken"]
[null,null,"Use one or more of the threading.is_alive(), threading.active_count(), and threading.enumerate() methods to determine if a thread’s execution state is as-expected"]
[null,null,"Protect data that would be vulnerable to premature termination, such as by using locks or protected regions, or by retaining the last consistent version of the data"]
[null,null,"Handle exceptions and clean up nested threads and potentially shared data before termination"]
[6.63,"Lock Protocol Errors [CGM","If global variables are used in multi-threaded code, be sure to use locks around them. Identify all locations where locks should be used but realize that the use of locks does not guarantee security since locks are only effective if all other threads check for the locks. A locked critical section in one thread can be modified by another thread if it does not first check for the lock"]
[null,null,"Verify that all sections of code that have access to critical sections check for a lock prior to using the data"]
[null,null,"When using global variables in multi-threaded code, use threading_local() which creates a local copy of the global variable within each thread"]
[null,null,"When using multiple threads, consider using semaphores to manage access to critical sections of data"]
[6.64,"Reliance on External Format String  [SHL]","Limit the size of input strings"]
[null,null,"Limit the number of input arguments to the expected values"]
[null,null,"Review the Python format string specifiers and do not allow formats that should not be input by the user"]

{"sheet":"Section 5 (First Draft)","index":1,"n_rows":77,"n_cols":6,"rows_kept":77,"merged":[[1,0,2,0],[1,1,2,1],[1,3,2,3],[1,4,2,4],[1,5,2,5],[3,0,5,0],[3,1,5,1],[3,3,5,3],[3,4,5,4],[3,5,5,5],[6,0,7,0],[6,1,7,1],[6,3,7,3],[6,4,7,4],[6,5,7,5],[8,0,10,0],[8,1,10,1],[8,3,10,3],[8,4,10,4],[8,5,10,5],[11,0,12,0],[11,1,12,1],[11,3,12,3],[11,4,12,4],[11,5,12,5],[13,0,16,0],[13,1,16,1],[13,3,16,3],[13,4,16,4],[13,5,16,5],[17,0,18,0],[17,1,18,1],[17,3,18,3],[17,4,18,4],[17,5,18,5],[19,0,20,0],[19,1,20,1],[19,3,20,3],[19,4,20,4],[19,5,20,5],[21,0,22,0],[21,1,22,1],[21,3,22,3],[21,4,22,4],[21,5,22,5],[23,0,24,0],[23,1,24,1],[23,3,24,3],[23,4,24,4],[23,5,24,5],[26,0,28,0],[26,1,28,1],[26,3,28,3],[26,4,28,4],[26,5,28,5],[29,0,31,0],[29,1,31,1],[29,3,31,3],[29,4,31,4],[29,5,31,5],[32,0,39,0],[32,1,39,1],[32,3,39,3],[32,4,39,4],[32,5,39,5],[40,0,42,0],[40,1,42,1],[40,3,42,3],[40,4,42,4],[40,5,42,5],[43,0,50,0],[43,1,50,1],[43,3,50,3],[43,4,50,4],[43,5,50,5],[51,0,58,0],[51,1,58,1],[51,3,58,3],[51,4,58,4],[51,5,58,5],[59,0,61,0],[59,1,61,1],[59,3,61,3],[59,4,61,4],[59,5,61,5],[62,0,76,0],[62,1,76,1],[62,3,76,3],[62,4,76,4],[62,5,76,5]]}
["No.","Reference(s)","Top Guidance (Highlighted)\n(General/Python Specific)","Rewritten\n(General/Python-Specific)","Comments","Priority"]
[1,6.5,"Be aware that assigning a list of names to integers is not safe since the variable can be bound to another object at any time.","Use the enum module that was introduced in Python v3.4 for better reliability and safety.","Update the main Python document and eliminate \"new\" so that it does not become dated \n\nReworded slightly - to emphasize the break-in point for the enum module\n\n. "]
[null,null,"Use the new enum module for better reliability and safety"]
[2,6.15,"Be cognizant that most arithmetic and bit manipulation operations on non-integers have the potential for undetected wrap-around errors.","Test the implementation that you are using to see if exceptions are raised for floating point operations and if they are, then use exception handling to catch and handle wrap-around errors.","The third guidance is all-encompassing reducing the need to mention the other two guidances. "]
[null,null,"Avoid using floating point or decimal variables for loop control but if you must use these types then bound the loop structures so as to not exceed the maximum or minimum possible values for the loop control variables."]
[null,null,"Test the implementation that you are using to see if exceptions are raised for floating point operations and if they are then use exception handling to catch and handle wrap-around errors."]
[3,6.24,"Be aware of Python’s short-circuiting behaviour when expressions with side effects are used on the right side of a Boolean expression","Be aware of potential short-circuiting behaviour when expressions with side effects are used on the right side of a Boolean expression. Use the assert statement during the debugging phase of code development to help eliminate undesired conditions from occurring.","Reworded slightly"]
[null,null,"Use the assert statement during the debugging phase of code development to help eliminate undesired conditions from occurring."]
[4,6.25,"Add parentheses after a function call in order to invoke the function.","Be aware that any function that changes a mutable object in place returns a None object – not the changed object since there is no need to return an object because the object has been changed by the function. \n\nBe sure to use an await statement for async coroutines and ensure that all routines are nonblocking","The two guidance referrences are not related but are more likely to occur and more likely to have vulnerability implications. \n\nReworded slightly"]
[null,null,"Keep in mind that any function that changes a mutable object in place returns a None object – not the changed object since there is no need to return an object because the object has been changed by the function."]
[null,null,"Be sure to use an await statement for async coroutines and ensure that all routines are nonblocking"]
[5,"6.28, 6.56, 6.57","Use only spaces or tabs, not both, to indent to demark control flow","Python v3 and greater disallows mixing the use of tabs and spaces for indentation and do not use form feed characters for indentation. Consider using the -tt command line option to raise an IndentationError in Python 2.7. Consider using a text editor to find and make consistent, the use of tabs and spaces for indentation.","Consolidated like-guidance from other sections. \n\nReworded"]
[null,null,"Note: Python 3.0+ will refuse to compile code that uses a mixture of tabs and spaces for indentation"]
[6,"6.33, 6.34","Avoid using ctypes when calling C code from within Python and use cffi (C Foreign Function Interface) instead","Avoid using ctypes when calling C code from within Python and use cffi (C Foreign Function Interface) instead since it is more streamlined and safer.","Combine 6.33 and 6.34"]
[null,null,"Avoid using ctypes when calling C code from within Python and use cffi (C Foreign Function Interface) instead since it is more streamlined and safer"]
[null,null,"Document the expected types of the formal parameters (type hints) and apply static analysis tools that check the program for correct usage of types"]
[null,null,"Use type membership tests to prevent runtime exceptions due to unexpected parameter types"]
[7,6.36,"Use Python’s exception handling with care in order to not catch errors that are intended for other exception handlers, i.e. always catch named exceptions","Use Python’s exception handling with care in order to not catch errors that are intended for other exception handlers, i.e. always catch named exceptions."]
[null,null,"Use exception handling, but directed to specific tolerable exceptions, to ensure that crucial processes can continue to run even after certain exceptions are raised"]
[8,6.38,"Use the “slice” operator [:] or container copy() methods to force a copy up to one nested level.    Note: x = y[:] or x = y.copy() copies the complete next level, but leaves deeper levels, such as sublists shared.","Use the “slice” operator [:] or container copy() methods to force a copy up to one nested level. Note: x = y[:] or x = y.copy() copies the complete next level, but leaves deeper levels, such as sublists shared. To force deep copies at all levels of a variable, use the “copy.deepcopy” standard library function. "]
[null,null,"To force deep copies at all levels of a variable, use the “copy.deepcopy” standard library function. "]
[9,6.39,"Release each object when it is no longer required. ","Release objects when they are no longer needed and use context managers to explicitly release large memory buffers that are no longer needed.","Reworded slightly"]
[null,null,"Use context managers to explicitly release large memory buffers that are no longer needed"]
[10,6.41,"Inherit only from trusted classes","Inherit only from trusted classes"]
[null,null,"Use Python’s built-in documentation (such as docstrings) to obtain information about a class’ methods before inheriting from the class"]
[11,6.42,"Use static analysis tools, either commercial or provided by the Python community to detect Liskov substitution violations","Use static analysis tools, either commercial or provided by the Python community, to detect Liskov substitution violations."]
[12,6.47,"Do not write Python extension modules by hand, as doing so is error-prone, and highly likely to lead to reference counting errors, memory leaks, dangling pointers, out-of-bounds memory accesses, and similar problems","Where available, use existing Python interface libraries such as PyO3 for Rust, pybind11 for C++, etc. Do not write Python extension modules by hand, as doing so is error-prone, and highly likely to lead to reference counting errors, memory leaks, dangling pointers, out-of-bounds memory accesses, and similar problems. Use libraries and tools that automatically generate the Python interface code from simpler descriptions of intent, such as Cython, cffi, and SWIG. ","Reworded"]
[null,null,"Python maintainers recommend that developers use existing libraries and tools that automatically generate the Python interface code from simpler descriptions of intent, such as those covered in https://packaging.python.org/guides/packaging-binary-extensions/  such as Cython, cffi, and SWIG."]
[null,null,"Where available, use existing interface libraries that bridge between Python and the extension module language, for example, PyO3 for Rust, pybind11 for C++. "]
[13,6.48,"Avoid using exec or eval and never use these with untrusted code","Ensure that the file path and files being imported are from trusted sources and avoid using exec or eval.","Reworded"]
[null,null,"Be careful when using Guerrilla patching to ensure that all uses of the patched classes and/or modules continue to function as expected; conversely, be aware of any code that patches classes and/or modules that your code is using to avoid unexpected results"]
[null,null,"Ensure that the file path and files being imported are from trusted sources."]
[14,6.54,"Ensure that a function is defined before attempting to call it","Be aware that a function is defined dynamically so its composition and operation may vary due to variations in the flow of control within the defining program. Do not use mutable objects as default values for arguments in a function definition unless you absolutely need to and you understand the effect. Also be aware that the when the += operatation is performed on mutable objects the operation is done in place and asignments to objects always create a new object. ","Reworded"]
[null,null,"Be aware that a function is defined dynamically so its composition and operation may vary due to variations in the flow of control within the defining program"]
[null,null,"Be aware of when a variable is local versus global"]
[null,null,"Do not use mutable objects as default values for arguments in a function definition unless you absolutely need to and you understand the effect."]
[null,null,"Be aware that when using the += operator on mutable objects the operation is done in place"]
[null,null,"Be cognizant that assignments to objects, mutable and immutable, always create a new object"]
[null,null,"Understand the difference between equivalence and equality and code accordingly"]
[null,null,"Ensure that the file path used to locate a persisted file or DBMS is correct and never ingest objects from an untrusted source."]
[15,6.55,"Do not rely on the content of error messages – use exception objects instead","Do not depend on the way Python may or may not optimize object references for small integer and string objects because it may vary for environments or even for releases in the same environment. \n\nWhen persisting object uses pickling, implement exception handling to cleanup partially written files.","Correct the grammar in the original documet, possibly to: \"When persisting object uses pickling, implement exception handling to cleanup partially written files.\"\n\nReworded"]
[null,null,"When persisting object using pickling use exception handling to cleanup partially written files"]
[null,null,"Do not depend on the way Python may or may not optimize object references for small integer and string objects because it may vary for environments or even for releases in the same environment"]
[16,6.56,"Understand the difference between testing for equivalence (for example, ==) and equality (for example, is) and do not depend on object identity tests to pass or fail when the variables reference immutable objects","In version prior to Python v3.7, do not depend on the sequence of keys in a dictionary to be consistent across implementations or even between multiple executions with the same implementation.","One top guidance reference in this section applies to indentation and is referenced in 6.28. \n\nReworded"]
[null,null,"Do not depend on the sequence of keys in a dictionary to be consistent across implementations, or even between multiple executions with the same implementation,  in versions prior to Python 3.7"]
[null,null,"When launching parallel tasks do not raise a BaseException subclass in a callable in the Future class"]
[null,null,"Do not modify the dictionary object returned by a vars call"]
[null,null,"Do not use form feed characters for indentation"]
[null,null,"Consider using the id function to test for object equality"]
[null,null,"Do not try to use the catch_warnings function to suppress warning messages when using more than one thread"]
[null,null,"Do not inspect or change the content of a list when sorting a list using the sort() method"]
[17,6.57,"Always use either spaces or tabs (but not both) for indentations","Ref. 6.28","One top guidance reference in this section applies to indentation and is referenced in 6.28. "]
[null,null,"Consider using the -tt command line option to raise an IndentationError in Python 2.7 (3.x will do this automatically)"]
[null,null,"Consider using a text editor to find and make consistent, the use of tabs and spaces for indentation"]
[null,null,"Either avoid logic that depends on byte order or use the sys.byteorder variable and write the logic to account for byte order dependent on its value ('little' or 'big')"]
[null,null,"Use zero (the default exit code for Python) for successful execution and consider adding logic to vary the exit code according to the platform as obtained from sys.platform (such as, 'win32', 'darwin', or other)"]
[null,null,"Interrogate the sys.float.info system variable to obtain platform specific attributes and code according to those constraints"]
[null,null,"Call  the sys.getfilesystemcoding() function to return the name of the encoding system used"]
[null,null,"When high performance is dependent on knowing the range of integer numbers that can be used without degrading performance use the sys.int_info struct sequence to obtain the number of bits per digit (bits_per_digit) and the number of bytes used to represent a digit (sizeof_digit)"]
[18,{"v":6.6,"d":"6.60"},"Avoid killing threads except as an extreme measure","Avoid killing threads except as an extreme measure. If killing a thread is deemed necessary, the preferred method is to terminate it from within the thread itself using a watchdog message queue or global variable that signals the thread to terminate itself. This will enable the thread to perform proper cleanup and eliminate deadlocks","Reworded"]
[null,null,"If necessary, the preferred method for killing a thread is from within the thread itself using a watchdog message queue or global variable that signals the thread to terminate itself. This will enable the thread to perform proper cleanup and eliminate deadlocks"]
[null,null,"Use care when terminating processes since finally clauses will not be executed, and descendant processes will not be terminated.  Design the code to be fail-safe since terminating a process may corrupt data associated with pipes and queues"]
[19,6.61,"Use join() to ensure that the calling thread is blocked until all joined threads have either terminated normally, thrown an exception, or timed out (if implemented)","Ensure that join() is not used on a thread before it is started since this will throw an exception and verify that no thread is waiting on daemon threads to complete since these threads are always running and could cause a deadlock. Use join() to ensure that the calling thread is blocked until all joined threads have either terminated normally, thrown an exception, or timed out (if implemented).  When using Async IO, all tasks must be non-blocking and use Async IO calls from an event loop. Locks and other synchronization techniques are usually not needed when implementing Async IO.","Reworded"]
[null,null,"Ensure that join() is not used on a thread before it is started since this will throw an exception"]
[null,null,"Verify that the opportunity does not exist for any thread to perform multiple joins since this would result in a deadlock condition"]
[null,null,"Ensure that no thread is waiting on daemon threads to complete since these threads are always running"]
[null,null,"Performing a join() on a daemon thread will result in a deadlock condition and it is recommended to use a join() on the message queue instead"]
[null,null,"If two or more items need to occur sequentially, ensure that they are ordered correctly and reside in the same thread, or provide synchronization between the two items in different threads"]
[null,null,"When using multiple processes, avoid using global variables and consider using the multiprocessing.Queue() function to share data between processes"]
[null,null,"When using multiple threads, avoid using global variables and consider using the queue.Queue() function to share data between threads"]
[null,null,"When using multiple threads, verify that no unprotected data is used directly by more than one thread"]
[null,null,"When using multiple threads, consider using the ThreadPoolExecutor within the concurrent.futures module to help maintain and control the number of threads being implemented"]
[null,null,"When using multiple threads, check for race conditions and deadlocks by using fuzzing techniques during development"]
[null,null,"If shared variables must be used in multithreaded applications, use model checking or equivalent methodologies to prove the absence of race conditions"]
[null,null,"For all new applications that require concurrency, consider using Async IO instead of threads or processes whenever possible. The reliability, speed, and maintainability of Async IO code is superior even though there is a steep learning curve"]
[null,null,"When converting existing code to Async IO, yield and await statements must be added to the code"]
[null,null,"When using Async IO, all tasks must be non-blocking and use Async IO calls from an event loop. Locks and other synchronization techniques are usually not needed when implementing Async IO"]